import java.util.*;
import java.util.stream.Collectors;

class Event implements Comparable<Event> {
    String name;
    Set<String> participants;

    public Event(String name, Set<String> participants) {
        this.name = name;
        this.participants = participants;
    }

    @Override
    public int compareTo(Event other) {
        return this.participants.size() - other.participants.size();
    }
}

public class AthleticsSchedule {
    public static void main(String[] args) {
        Map<String, List<String>> participantEvents = new HashMap<>();
        participantEvents.put("丁一", Arrays.asList("跳高", "跳远", "100米"));
        participantEvents.put("马二", Arrays.asList("标枪", "铅球"));
        participantEvents.put("张三", Arrays.asList("标枪", "200米"));
        participantEvents.put("李四", Arrays.asList("铅球", "跳高"));
        participantEvents.put("王五", Arrays.asList("跳远", "200米"));

        Map<String, Set<String>> eventParticipants = new HashMap<>();
        for (Map.Entry<String, List<String>> entry : participantEvents.entrySet()) {
            for (String event : entry.getValue()) {
                eventParticipants.computeIfAbsent(event, k -> new HashSet<>()).add(entry.getKey());
            }
        }

        List<Event> events = new ArrayList<Event>(eventParticipants.keySet().stream().map(e -> new Event(e, eventParticipants.get(e))).collect(Collectors.toList()));
        events.sort(null);

        Map<String, Integer> participantCount = new HashMap<>();
        for (String participant : participantEvents.keySet()) {
            participantCount.put(participant, 0);
        }

        List<String> schedule = new ArrayList<>();
        int eventTime = 0;

        while (!events.isEmpty()) {
            boolean added = false;
            List<Event> toBeAdded = new ArrayList<>();
            for (Event event : events) {
                if (isFree(event, schedule, participantCount)) {
                    toBeAdded.add(event);
                    added = true;
                }
            }
            if (added) {
                for (Event event : toBeAdded) {
                    schedule.add(event.name);
                    for (String participant : event.participants) {
                        participantCount.put(participant, participantCount.get(participant) + 1);
                    }
                    events.remove(event);
                }
                eventTime++;
            } else {
                eventTime++; // No event could be added, move to next time slot
            }
        }

        System.out.println("Schedule:");
        for (int i = 0; i < schedule.size(); i++) {
            System.out.println("Time " + i + ": " + schedule.get(i));
        }
    }

    private static boolean isFree(Event event, List<String> schedule, Map<String, Integer> participantCount) {
        for (String participant : event.participants) {
            if (participantCount.get(participant) >= 3) {
                return false;
            }
        }
        return true;
    }
}